`timescale 1ns / 1ps
`define bullet_r 36
`define my_bullet_r 5
`define slow_v 1
`define fast_v 2

module MainLogic(
	input clk,
	input [15:0]SW,
	input ps2_clk, 
	input ps2_data,
	output hs,
	output vs,
	output [3:0] r,
	output [3:0] g,
	output [3:0] b,
	output wire [3:0] AN,
	output wire [7:0] SEGMENT,
	output wire SEGCLK,
	output wire SEGCLR,
	output wire SEGDT,
	output wire SEGEN
);
	
	reg [31:0]clkdiv;
	wire [15:0] SW_OK;
	
	reg [3:0] state; 	
	initial state = 0;
	reg [1:0] choose; 		
	initial choose = 0;
	
	reg [11:0] vga_data;
	wire [9:0] col_addr;//[9:0]
	wire [8:0] row_addr;//[8:0]
	
	(* DONT_TOUCH = "TRUE" *)wire [11:0] vga_data_back;
	(* DONT_TOUCH = "TRUE" *)wire [11:0] vga_data_gameback;
	(* DONT_TOUCH = "TRUE" *)wire [18:0] back_address;
	//(* DONT_TOUCH = "TRUE" *)wire [18:0] gameback_address;
	assign back_address = row_addr*640+col_addr;
	//assign gameback_address = row_addr*640+col_addr;
	
	
	wire [11:0] vga_data_arrow;	
	wire [10:0] arrow_address;//40x40 (276,44)
	assign arrow_address = (choose==0)?((row_addr-270)*40+col_addr-5):((row_addr-334)*40+col_addr-5);
	
	wire [11:0] vga_data_win;
	wire [13:0] win_addr;
	assign win_addr = (row_addr-190)*108+col_addr-270;
	
	wire [11:0] vga_data_lose;
	wire [13:0] lose_addr;
	assign lose_addr = (row_addr-190)*107+col_addr-270;
	
	wire [11:0] vga_data_info;
	wire [15:0] info_addr;
	assign info_addr = row_addr*274+col_addr;
	
	reg [9:0] player_dotx;
	reg [8:0] player_doty;
	wire [9:0] player_imgx;
	assign player_imgx = player_dotx-30;
	wire [8:0] player_imgy;
	assign player_imgy = player_doty-19;
	wire [11:0] vga_data_player;
	wire [11:0] player_img_addr;//63*44
	assign player_img_addr = (row_addr-player_imgy)*63+(col_addr-player_imgx);
	wire [3:0] attack;
	assign attack[0] = 1'b1;
	assign attack[1] = SW[12];
	assign attack[2] = SW[13];
	assign attack[3] = SW[14];
	
	reg [9:0] enermyx;
	initial enermyx = 210;
	reg [8:0] enermyy;
	initial enermyy = 16;
	wire [11:0] vga_data_enermy;
	wire [10:0] addr_enermy;
	assign addr_enermy = (row_addr-enermyy)*26+col_addr-enermyx;
	reg init_pos;
	initial init_pos = 1;
	reg init_direc;
	initial init_direc = 1;
	
	reg [7:0] key_has_press;
	initial key_has_press = 0;
	wire [9:0] keybd_code;
	wire ready; 

	reg [2:0] acc_x;
	initial acc_x = 0;
	reg [2:0] acc_y;
	initial acc_y = 0;
	
	reg [3:0] boss_state;
	initial boss_state = 0;
	reg [9:0] boss_hp;
	initial boss_hp = 639;
	reg [1:0] direc;
	initial direc = 0;
	reg hp_init;
	initial hp_init = 1;
	
	wire [9:0] ebx [38:0];
	wire [8:0] eby [38:0];
	wire [19:0] ebx2 [38:0];	//assign-block in the following code
	wire [19:0] eby2 [38:0];	//assign-block in the following code
	wire [38:0] hitme;			//assign-block in the following code
	
	wire dead_ptb;	//assign-block in the following code
	wire dead_hv;	//assign-block in the following code
	wire dead_sph;	//assign-block in the following code
	wire dead;		//assign-block in the following code
	
	reg [9:0] mbx [7:0];
	reg [8:0] mby [7:0];
	reg [7:0] bullet_cnt;
	initial bullet_cnt = 8'b1111_1111;
	reg [8:0] emit_delay;
	initial emit_delay = 0;
	
	wire [7:0] hitenermy;
	//initial hitenermy = 8'b0000_0000;
	wire [7:0] hite;	//assign-block in the following code
	
	wire bullet_ptb;	//assign-block in the following code
	wire bullet_sphere;	//assign-block in the following code
	wire bullet_hv;		//assign-block in the following code
	wire bullet_mode;	//assign-block in the following code
	
	wire win;
	assign win = (boss_hp==0)?1'b1:1'b0;
	
	wire mov_ptb;
	assign mov_ptb = (boss_state>=1)?1'b1:1'b0;
	wire [7:0] ptb_wait;
	wire ptb_all_wait;
	assign ptb_all_wait = 
		ptb_wait[0]&ptb_wait[3]&ptb_wait[4]&ptb_wait[7]&
		ptb_wait[1]&ptb_wait[2]&ptb_wait[5]&ptb_wait[6];
	wire mov_hv;
	assign mov_hv = (boss_state==0||boss_state>=2)?1'b1:1'b0;
	wire mov_sph;
	assign mov_sph = (boss_state==3)?1'b1:1'b0;
	wire [17:0] sph_wait;
	wire sph_all_wait;
	assign sph_all_wait = 
		sph_wait[0]&sph_wait[1]&sph_wait[4]&sph_wait[5]&sph_wait[8]&sph_wait[9]&
		sph_wait[2]&sph_wait[3]&sph_wait[6]&sph_wait[7]&sph_wait[10]&sph_wait[11]&
		sph_wait[14]&sph_wait[15]&sph_wait[16]&sph_wait[17]&sph_wait[12]&sph_wait[13];

	
	wire[31:0] num; 
	assign num={
		3'b0,key_has_press[7],
		3'b0,key_has_press[6],
		3'b0,key_has_press[5],
		3'b0,key_has_press[4],
		3'b0,key_has_press[3],
		3'b0,key_has_press[2],
		3'b0,key_has_press[1],
		3'b0,key_has_press[0]};
	wire[63:0] seg_display_bit;
	Num2Seg(.I(num),.O(seg_display_bit));
	L2S #(.DATA_BITS(64), .DIR(1)) 
		seg_p2s(.P_Data(seg_display_bit), .clk(clk), .rst(1'b0), .start(clkdiv[20]),.sout(SEGDT), .sclk(SEGCLK), .sclrn(SEGCLR), .sen(SEGEN));
	
	always@(posedge clk) clkdiv <= clkdiv + 1'b1;
	AntiJitter #(4) a0[15:0](.clk(clkdiv[15]), .I(SW), .O(SW_OK));
	StartPage 		img0(.clka(clk), .addra(back_address), .douta(vga_data_back));
	ArrowImage 		img1(.clka(clk), .addra(arrow_address), .douta(vga_data_arrow));
	GamePage 		img2(.clka(clk), .addra(back_address), .douta(vga_data_gameback));
	Player1Image 	player1(.clka(clk),.addra(player_img_addr),.douta(vga_data_player));
	EnermyImage 	enermy1(.clka(clk), .addra(addr_enermy), .douta(vga_data_enermy));
	WinImage		win0(.clka(clk),.addra(win_addr),.douta(vga_data_win));
	LoseImage		lose0(.clka(clk),.addra(lose_addr),.douta(vga_data_lose));
	InfoPage		info0(.clka(clk),.addra(info_addr),.douta(vga_data_info));
	vgac 			v0(	.vga_clk(clkdiv[1]),.clrn(1'b1),.d_in(vga_data),
						.row_addr(row_addr[8:0]),.col_addr(col_addr[9:0]),
						.r(r),.g(g),.b(b),.hs(hs),.vs(vs));
	
	disp_num
		display(.clk(clk),.HEXS({state,boss_state,3'b0,SW[15],attack}), 
				.LES(4'b0000),.points(4'b1111),.RST(1'b0), 
				.AN(AN),.Segment(SEGMENT));

	
	//keyboard input module - no-conflict for all used keys
	ps2_ver2 
		m0(.clk(clk),.rst(SW_OK[1]),.ps2_clk(ps2_clk),.ps2_data(ps2_data),.data_out(keybd_code),.ready(ready));
	always @ (posedge clk) begin
		if (ready) begin
			if (keybd_code[8]) begin
				case(keybd_code[7:0])
					8'h1A:key_has_press[7]<=1'b0;//z
					8'h12:key_has_press[6]<=1'b0;//left shift
					8'h76:key_has_press[5]<=1'b0;//esc
					8'h5A:key_has_press[4]<=1'b0;//enter
					8'h75:key_has_press[3]<=1'b0;//up
					8'h72:key_has_press[2]<=1'b0;//down
					8'h6B:key_has_press[1]<=1'b0;//left
					8'h74:key_has_press[0]<=1'b0;//right
					default:;
				endcase
			end
			else begin
				case(keybd_code[7:0])
					8'h1A:key_has_press[7]<=1'b1;
					8'h12:key_has_press[6]<=1'b1;
					8'h76:key_has_press[5]<=1'b1;
					8'h5A:key_has_press[4]<=1'b1;
					8'h75:key_has_press[3]<=1'b1;
					8'h72:key_has_press[2]<=1'b1;
					8'h6B:key_has_press[1]<=1'b1;
					8'h74:key_has_press[0]<=1'b1;
					default:;
				endcase				
			end
		end
	end
	
	
	//game state block
	always @ (posedge clkdiv[18]) begin
		if (state == 0) begin
			if (key_has_press[3]&&choose == 1)choose <= 0;
			if (key_has_press[2]&&choose == 0)choose <= 1;
			if (key_has_press[4]&&choose == 0)begin
				state <= 1;
				boss_hp <= 639;
				boss_state <= 0;
				direc <= 0;
				enermyx <= 210;
				enermyy <= 16;
				player_dotx <= 320;
				player_doty <= 400;
			end
			if (choose == 1&&key_has_press[4])choose <=2;
			if (choose == 2&&key_has_press[5])choose <= 0;
		end else if (state == 1) begin
			if (key_has_press[5]) begin
				state <= 0;
			end else if (dead) begin
				state <= 3;
			end else if (win) begin
				state <= 2;
			end else if (init_pos) begin
				enermyx <= 210;
				enermyy <= 16;
				init_pos<=0;				
			end else begin
				if (key_has_press) begin
					if (key_has_press[3]|key_has_press[2]) begin
						if (acc_y<`fast_v) acc_y<=acc_y+1;
					end else begin
						acc_y <= 0;
					end
					if (key_has_press[1]|key_has_press[0]) begin
						if (acc_x<`fast_v) acc_x<=acc_x+1;
					end else begin
						acc_x <= 0;
					end
					//left up:(32, 16)
					//left down:(32,463)
					//right down:(415,463)
					//right up:(415,16)
					if (key_has_press[3]) begin//up
						if (player_doty>=16+(`slow_v+acc_y)&&~key_has_press[6]) player_doty <= player_doty-(`slow_v+acc_y);
						else if (player_doty>=16+`slow_v&&key_has_press[6])player_doty<=player_doty-`slow_v;
					end
					if (key_has_press[2]) begin//down
						if (player_doty<463-(`slow_v+acc_y)&&~key_has_press[6]) player_doty <= player_doty+(`slow_v+acc_y);
						else if (player_doty<463-`slow_v&&key_has_press[6])player_doty<=player_doty+`slow_v;
					end
					if (key_has_press[1]) begin//left
						if (player_dotx>=32+(`slow_v+acc_x)&&~key_has_press[6]) player_dotx <= player_dotx-(`slow_v+acc_x);
						else if (player_dotx>=32+`slow_v&&key_has_press[6])player_dotx<=player_dotx-`slow_v;
					end
					if (key_has_press[0]) begin//right
						if (player_dotx<415-(`slow_v+acc_x)&&~key_has_press[6]) player_dotx <= player_dotx+(`slow_v+acc_x);
						else if (player_dotx<415-`slow_v&&key_has_press[6])player_dotx<=player_dotx+`slow_v;
					end
				end
				
				if (boss_state == 2&&boss_hp<220) begin
					boss_state <= 4;
				end
				else if (boss_state == 4) begin
					direc <= 0;
					enermyx <= 210;
					enermyy <= 90;
					boss_state <= 3;
				end else begin
					if (boss_hp >= 539) begin
						boss_state <= 0;
					end else if (boss_hp >= 400) begin 
						boss_state <= 1;
					end else if (boss_hp >= 220) begin
						boss_state <= 2;
					end else if (boss_hp >= 0) begin
						boss_state <= 3;
					end
				end
				if (boss_state == 3) begin
					if (direc==0) begin
						if (enermyx < 300) begin
							enermyx <= enermyx+1;
							enermyy <= enermyy+1;
						end else begin
							direc <= 1;
						end
					end else if (direc==1) begin
						if (enermyx > 120) begin
							enermyx <= enermyx-1;
						end else begin
							direc <= 2;
						end
					end else begin
						if (enermyx == 210) begin
							direc <= 0;
						end else begin
							enermyx <= enermyx+1;
							enermyy <= enermyy-1;
						end
					end
				end else if (boss_state == 2) begin
					if (direc==0) begin
						if (enermyx < 380) begin
							enermyx <= enermyx+1;
						end else begin
							direc <= 1;
						end
					end else begin
						if (enermyx > 40) begin
							enermyx <= enermyx-1;
						end else begin
							direc <= 0;
						end
					end
				end
			end
		end
		else if (state == 2) begin
			if (key_has_press[5]) state <=0;
		end 
		else if (state == 3) begin
			if (key_has_press[5]) state <=0;
		end
		
		
		
		if (key_has_press[7]) begin
			emit_delay <= emit_delay+1;
			if (bullet_cnt==8'b1111_1111) begin
				emit_delay <= 11;
			end
			if (bullet_cnt&&emit_delay==11) begin
				if (bullet_cnt[0]) begin
					bullet_cnt[0] <= 0;
					mbx[0] <= player_dotx;
					mby[0] <= player_doty;
					emit_delay <=0;
				end else if (bullet_cnt[1]) begin
					bullet_cnt[1] <= 0;
					mbx[1] <= player_dotx;
					mby[1] <= player_doty;
					emit_delay <=0;
				end else if (bullet_cnt[2]) begin
					bullet_cnt[2] <= 0;
					mbx[2] <= player_dotx;
					mby[2] <= player_doty;
					emit_delay <=0;
				end else if (bullet_cnt[3]) begin
					bullet_cnt[3] <= 0;
					mbx[3] <= player_dotx;
					mby[3] <= player_doty;
					emit_delay <=0;
				end else if (bullet_cnt[4]) begin
					bullet_cnt[4] <= 0;
					mbx[4] <= player_dotx;
					mby[4] <= player_doty;
					emit_delay <=0;
				end else if (bullet_cnt[5]) begin
					bullet_cnt[5] <= 0;
					mbx[5] <= player_dotx;
					mby[5] <= player_doty;
					emit_delay <=0;
				end else if (bullet_cnt[6]) begin
					bullet_cnt[4] <= 0;
					mbx[6] <= player_dotx;
					mby[6] <= player_doty;
					emit_delay <=0;
				end else if (bullet_cnt[7]) begin
					bullet_cnt[7] <= 0;
					mbx[7] <= player_dotx;
					mby[7] <= player_doty;
					emit_delay <=0;
				end				
			end
		end
		if (~bullet_cnt[0]) begin
			if (hite[0]) begin
				bullet_cnt[0] <= 1;
				if (boss_hp>=attack) boss_hp <= boss_hp-attack;
				else boss_hp<=0;
			end
			else if (mby[0]>=18) mby[0] <= mby[0] - 5;
			else bullet_cnt[0] <= 1;
		end
		if (~bullet_cnt[1]) begin
			if (hite[1]) begin
				bullet_cnt[1] <= 1;
				if (boss_hp>=attack) boss_hp <= boss_hp-attack;
				else boss_hp<=0;
			end
			else if (mby[1]>=18) mby[1] <= mby[1] - 5;
			else bullet_cnt[1] <= 1;
		end
		if (~bullet_cnt[2]) begin
			if (hite[2]) begin
				bullet_cnt[2] <= 1;
				if (boss_hp>=attack) boss_hp <= boss_hp-attack;
				else boss_hp<=0;
			end
			else if (mby[2]>=18) mby[2] <= mby[2] - 5;
			else bullet_cnt[2] <= 1;
		end
		if (~bullet_cnt[3]) begin
			if (hite[3]) begin
				bullet_cnt[3] <= 1;
				if (boss_hp>=attack) boss_hp <= boss_hp-attack;
				else boss_hp<=0;
			end
			else if (mby[3]>=18) mby[3] <= mby[3] - 5;
			else bullet_cnt[3] <= 1;
		end
		if (~bullet_cnt[4]) begin
			if (hite[4]) begin 
				bullet_cnt[4] <= 1;
				if (boss_hp>=attack) boss_hp <= boss_hp-attack;
				else boss_hp<=0;
			end
			else if (mby[4]>=18) mby[4] <= mby[4] - 5;
			else bullet_cnt[4] <= 1;
		end
		if (~bullet_cnt[5]) begin
			if (hite[5]) begin
				bullet_cnt[5] <= 1;
				if (boss_hp>=attack) boss_hp <= boss_hp-attack;
				else boss_hp<=0;
			end
			else if (mby[5]>=18) mby[5] <= mby[5] - 5;
			else bullet_cnt[5] <= 1;
		end
		if (~bullet_cnt[6]) begin
			if (hite[6]) begin
				bullet_cnt[6] <= 1;
				if (boss_hp>=attack) boss_hp <= boss_hp-attack;
				else boss_hp<=0;
			end
			else if (mby[6]>=18) mby[6] <= mby[6] - 5;
			else bullet_cnt[6] <= 1;
		end 		
		if (~bullet_cnt[7]) begin
			if (hite[7]) begin
				bullet_cnt[7] <= 1;
				if (boss_hp>=attack) boss_hp <= boss_hp-attack;
				else boss_hp<=0;
			end
			else if (mby[7]>=18) mby[7] <= mby[7] - 5;
			else bullet_cnt[7] <= 1;
		end
	end
	
	//display - module
	always@(posedge clk) begin
		if (state == 0) begin
			if (choose == 0) begin
				if (col_addr>=10'd5&&col_addr<10'd45&&row_addr>=9'd270&&row_addr<9'd310) begin
					if (vga_data_arrow==12'hfff) vga_data <= vga_data_back;
					else begin
						vga_data <= vga_data_arrow;
					end
				end
				else if (col_addr>=0&&col_addr<640&&row_addr>=0&&row_addr<480) begin
					vga_data <= vga_data_back;
				end
			end
			else if (choose == 1) begin
				if (col_addr>=5&&col_addr<45&&row_addr>=334&&row_addr<374) begin
					if (vga_data_arrow==12'hfff) vga_data <= vga_data_back;
					else begin
						vga_data <= vga_data_arrow;
					end
				end
				else if (col_addr>=0&&col_addr<640&&row_addr>=0&&row_addr<480) begin
					vga_data <= vga_data_back;
				end
			end
			else if (choose == 2) begin
				if (col_addr>=0&&row_addr>=0&&col_addr<274&&row_addr<208)
					vga_data <= vga_data_info;
				else
					vga_data <= 12'hfff;
				end
			else begin
				if (col_addr>=0&&col_addr<640&&row_addr>=0&&row_addr<480) begin
					vga_data <= vga_data_back;
				end
			end
		end
		else if (state == 1) begin
			if (col_addr>=0&&col_addr<640&&row_addr>=0&&row_addr<480) begin
				if (col_addr>=0&&col_addr<=boss_hp&&row_addr>=0&&row_addr<=10) begin
					vga_data <= 12'h00f;
				end
				else if (
					(~bullet_cnt[0]&&(col_addr>=mbx[0]&&col_addr<mbx[0]+`my_bullet_r&&row_addr>=mby[0]&&row_addr<mby[0]+`my_bullet_r))||
					(~bullet_cnt[1]&&(col_addr>=mbx[1]&&col_addr<mbx[1]+`my_bullet_r&&row_addr>=mby[1]&&row_addr<mby[1]+`my_bullet_r))||
					(~bullet_cnt[2]&&(col_addr>=mbx[2]&&col_addr<mbx[2]+`my_bullet_r&&row_addr>=mby[2]&&row_addr<mby[2]+`my_bullet_r))||
					(~bullet_cnt[3]&&(col_addr>=mbx[3]&&col_addr<mbx[3]+`my_bullet_r&&row_addr>=mby[3]&&row_addr<mby[3]+`my_bullet_r))||
					(~bullet_cnt[4]&&(col_addr>=mbx[4]&&col_addr<mbx[4]+`my_bullet_r&&row_addr>=mby[4]&&row_addr<mby[4]+`my_bullet_r))||
					(~bullet_cnt[5]&&(col_addr>=mbx[5]&&col_addr<mbx[5]+`my_bullet_r&&row_addr>=mby[5]&&row_addr<mby[5]+`my_bullet_r))||
					(~bullet_cnt[6]&&(col_addr>=mbx[6]&&col_addr<mbx[6]+`my_bullet_r&&row_addr>=mby[6]&&row_addr<mby[6]+`my_bullet_r))||
					(~bullet_cnt[7]&&(col_addr>=mbx[7]&&col_addr<mbx[7]+`my_bullet_r&&row_addr>=mby[7]&&row_addr<mby[7]+`bullet_r))
				) begin
					vga_data <= 12'h0ff;
				end else if (bullet_mode) begin
					vga_data <= 12'hfff;
				end
				else if (col_addr>=player_imgx&&col_addr<player_imgx+63&&row_addr>=player_imgy&&row_addr<player_imgy+44) begin
					if (vga_data_player==12'hfff) begin
						if (col_addr>=enermyx&&col_addr<enermyx+26&&row_addr>=enermyy&&row_addr<enermyy+50)
							if (vga_data_enermy==12'hfff) vga_data <= vga_data_gameback;
							else vga_data <= vga_data_enermy;
						else vga_data <= vga_data_gameback;
					end
					else vga_data <= vga_data_player;
				end else if (col_addr>=enermyx&&col_addr<enermyx+26&&row_addr>=enermyy&&row_addr<enermyy+50) begin
					if (vga_data_enermy==12'hfff) vga_data <= vga_data_gameback;
					else vga_data <= vga_data_enermy;
				end
				else vga_data <= vga_data_gameback;
			end
		end
		else if (state == 2) begin
			if (col_addr>=270&&row_addr>=190&&col_addr<378&&row_addr<291)
				vga_data <= vga_data_win;
			else
				vga_data <= 12'h000;
		end else if (state == 3) begin
			if (col_addr>=270&&row_addr>=190&&col_addr<377&&row_addr<294)
				vga_data <= vga_data_lose;
			else
				vga_data <= 12'h000;
		end
	end


	//enermy bullet (x,y) driver
	//player-towards bullet
	RDMM
		t0(.enable(mov_ptb),.outwait(ptb_all_wait),.speed(clkdiv[19]),.x0(10'd55), .y0(9'd16),.targetx(player_dotx),.targety(player_doty),.x(ebx[0]),.y(eby[0]),.inwait(ptb_wait[0])),
		t1(.enable(mov_ptb),.outwait(ptb_all_wait),.speed(clkdiv[19]),.x0(10'd105),.y0(9'd16),.targetx(player_dotx),.targety(player_doty),.x(ebx[1]),.y(eby[1]),.inwait(ptb_wait[1])),
		t2(.enable(mov_ptb),.outwait(ptb_all_wait),.speed(clkdiv[19]),.x0(10'd155),.y0(9'd16),.targetx(player_dotx),.targety(player_doty),.x(ebx[2]),.y(eby[2]),.inwait(ptb_wait[2])),
		t3(.enable(mov_ptb),.outwait(ptb_all_wait),.speed(clkdiv[19]),.x0(10'd200),.y0(9'd16),.targetx(player_dotx),.targety(player_doty),.x(ebx[3]),.y(eby[3]),.inwait(ptb_wait[3])),
		t4(.enable(mov_ptb),.outwait(ptb_all_wait),.speed(clkdiv[19]),.x0(10'd255),.y0(9'd16),.targetx(player_dotx),.targety(player_doty),.x(ebx[4]),.y(eby[4]),.inwait(ptb_wait[4])),
		t5(.enable(mov_ptb),.outwait(ptb_all_wait),.speed(clkdiv[19]),.x0(10'd295),.y0(9'd16),.targetx(player_dotx),.targety(player_doty),.x(ebx[5]),.y(eby[5]),.inwait(ptb_wait[5])),
		t6(.enable(mov_ptb),.outwait(ptb_all_wait),.speed(clkdiv[19]),.x0(10'd340),.y0(9'd16),.targetx(player_dotx),.targety(player_doty),.x(ebx[6]),.y(eby[6]),.inwait(ptb_wait[6])),
		t7(.enable(mov_ptb),.outwait(ptb_all_wait),.speed(clkdiv[19]),.x0(10'd390),.y0(9'd16),.targetx(player_dotx),.targety(player_doty),.x(ebx[7]),.y(eby[7]),.inwait(ptb_wait[7]));
	//hori
	RDMM
		h0(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd32), .y0(9'd120),.targetx(10'd415),.targety(9'd120),.x(ebx[8]),.y(eby[8])),
		h1(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd32), .y0(9'd220),.targetx(10'd415),.targety(9'd220),.x(ebx[9]),.y(eby[9])),
		h2(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd32), .y0(9'd320),.targetx(10'd415),.targety(9'd320),.x(ebx[10]),.y(eby[10])),
		h3(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd32), .y0(9'd420),.targetx(10'd415),.targety(9'd420),.x(ebx[11]),.y(eby[11])),
		h4(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd415), .y0(9'd170),.targetx(10'd32),.targety(9'd170),.x(ebx[12]),.y(eby[12])),
		h5(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd415), .y0(9'd270),.targetx(10'd32),.targety(9'd270),.x(ebx[13]),.y(eby[13])),
		h6(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd415), .y0(9'd370),.targetx(10'd32),.targety(9'd370),.x(ebx[14]),.y(eby[14])),
		h7(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd415), .y0(9'd450),.targetx(10'd32),.targety(9'd450),.x(ebx[15]),.y(eby[15]));
	//vertical
	RDMM
		v1(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd100), .y0(9'd462),.targetx(10'd100),.targety(9'd16),.x(ebx[16]),.y(eby[16])),
		v2(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd160), .y0(9'd462),.targetx(10'd160),.targety(9'd16),.x(ebx[17]),.y(eby[17])),
		v3(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd220), .y0(9'd462),.targetx(10'd220),.targety(9'd16),.x(ebx[18]),.y(eby[18])),
		v4(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd300), .y0(9'd462),.targetx(10'd300),.targety(9'd16),.x(ebx[19]),.y(eby[19])),
		v5(.enable(mov_hv),.outwait(1'b1),.speed(clkdiv[20]),.x0(10'd360), .y0(9'd462),.targetx(10'd360),.targety(9'd16),.x(ebx[20]),.y(eby[20]));
	//spherical
	RDMM
		s0(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx+82),.targety(enermyy),.x(ebx[21]),.y(eby[21]),.inwait(sph_wait[0])),
		s1(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx+77),.targety(enermyy+28),.x(ebx[22]),.y(eby[22]),.inwait(sph_wait[1])),
		s2(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx+63),.targety(enermyy+52),.x(ebx[23]),.y(eby[23]),.inwait(sph_wait[2])),
		s3(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx+41),.targety(enermyy+71),.x(ebx[24]),.y(eby[24]),.inwait(sph_wait[3])),
		s4(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx+14),.targety(enermyy+80),.x(ebx[25]),.y(eby[25]),.inwait(sph_wait[4])),
		s5(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx-14),.targety(enermyy+80),.x(ebx[26]),.y(eby[26]),.inwait(sph_wait[5])),
		s6(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx-41),.targety(enermyy+71),.x(ebx[27]),.y(eby[27]),.inwait(sph_wait[6])),
		s7(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx-63),.targety(enermyy+52),.x(ebx[28]),.y(eby[28]),.inwait(sph_wait[7])),
		s8(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx-77),.targety(enermyy+28),.x(ebx[29]),.y(eby[29]),.inwait(sph_wait[8])),
		s9(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx-82),.targety(enermyy),.x(ebx[30]),.y(eby[30]),.inwait(sph_wait[9])),
		s10(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx-77),.targety(enermyy-28),.x(ebx[31]),.y(eby[31]),.inwait(sph_wait[10])),
		s11(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx-63),.targety(enermyy-52),.x(ebx[32]),.y(eby[32]),.inwait(sph_wait[11])),
		s12(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx-41),.targety(enermyy-71),.x(ebx[33]),.y(eby[33]),.inwait(sph_wait[12])),
		s13(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx-14),.targety(enermyy-80),.x(ebx[34]),.y(eby[34]),.inwait(sph_wait[13])),
		s14(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx+14),.targety(enermyy-80),.x(ebx[35]),.y(eby[35]),.inwait(sph_wait[14])),
		s15(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx+41),.targety(enermyy-71),.x(ebx[36]),.y(eby[36]),.inwait(sph_wait[15])),
		s16(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx+63),.targety(enermyy-52),.x(ebx[37]),.y(eby[37]),.inwait(sph_wait[16])),
		s17(.enable(mov_sph),.outwait(sph_all_wait),.speed(clkdiv[18]),.x0(enermyx),.y0(enermyy),.targetx(enermyx+77),.targety(enermyy-28),.x(ebx[38]),.y(eby[38]),.inwait(sph_wait[17]));


	//bullet hit checker
	//enermy bullet
	CheckHit #(3)
			ch0(.clk(clkdiv[18]),.x0(ebx[0]),.y0(eby[0]),.x1(player_dotx),.y1(player_doty),.hit(hitme[0])),
			ch1(.clk(clkdiv[18]),.x0(ebx[1]),.y0(eby[1]),.x1(player_dotx),.y1(player_doty),.hit(hitme[1])),
			ch2(.clk(clkdiv[18]),.x0(ebx[2]),.y0(eby[2]),.x1(player_dotx),.y1(player_doty),.hit(hitme[2])),
			ch3(.clk(clkdiv[18]),.x0(ebx[3]),.y0(eby[3]),.x1(player_dotx),.y1(player_doty),.hit(hitme[3])),
			ch4(.clk(clkdiv[18]),.x0(ebx[4]),.y0(eby[4]),.x1(player_dotx),.y1(player_doty),.hit(hitme[4])),
			ch5(.clk(clkdiv[18]),.x0(ebx[5]),.y0(eby[5]),.x1(player_dotx),.y1(player_doty),.hit(hitme[5])),
			ch6(.clk(clkdiv[18]),.x0(ebx[6]),.y0(eby[6]),.x1(player_dotx),.y1(player_doty),.hit(hitme[6])),
			ch7(.clk(clkdiv[18]),.x0(ebx[7]),.y0(eby[7]),.x1(player_dotx),.y1(player_doty),.hit(hitme[7])),
			ch8(.clk(clkdiv[18]),.x0(ebx[8]),.y0(eby[8]),.x1(player_dotx),.y1(player_doty),.hit(hitme[8])),
			ch9(.clk(clkdiv[18]),.x0(ebx[9]),.y0(eby[9]),.x1(player_dotx),.y1(player_doty),.hit(hitme[9])),
			ch10(.clk(clkdiv[18]),.x0(ebx[10]),.y0(eby[10]),.x1(player_dotx),.y1(player_doty),.hit(hitme[10])),
			ch11(.clk(clkdiv[18]),.x0(ebx[11]),.y0(eby[11]),.x1(player_dotx),.y1(player_doty),.hit(hitme[11])),
			ch12(.clk(clkdiv[18]),.x0(ebx[12]),.y0(eby[12]),.x1(player_dotx),.y1(player_doty),.hit(hitme[12])),
			ch13(.clk(clkdiv[18]),.x0(ebx[13]),.y0(eby[13]),.x1(player_dotx),.y1(player_doty),.hit(hitme[13])),
			ch14(.clk(clkdiv[18]),.x0(ebx[14]),.y0(eby[14]),.x1(player_dotx),.y1(player_doty),.hit(hitme[14])),
			ch15(.clk(clkdiv[18]),.x0(ebx[15]),.y0(eby[15]),.x1(player_dotx),.y1(player_doty),.hit(hitme[15])),
			ch16(.clk(clkdiv[18]),.x0(ebx[16]),.y0(eby[16]),.x1(player_dotx),.y1(player_doty),.hit(hitme[16])),
			ch17(.clk(clkdiv[18]),.x0(ebx[17]),.y0(eby[17]),.x1(player_dotx),.y1(player_doty),.hit(hitme[17])),
			ch18(.clk(clkdiv[18]),.x0(ebx[18]),.y0(eby[18]),.x1(player_dotx),.y1(player_doty),.hit(hitme[18])),
			ch19(.clk(clkdiv[18]),.x0(ebx[19]),.y0(eby[19]),.x1(player_dotx),.y1(player_doty),.hit(hitme[19])),
			ch20(.clk(clkdiv[18]),.x0(ebx[20]),.y0(eby[20]),.x1(player_dotx),.y1(player_doty),.hit(hitme[20])),
			ch21(.clk(clkdiv[18]),.x0(ebx[21]),.y0(eby[21]),.x1(player_dotx),.y1(player_doty),.hit(hitme[21])),
			ch22(.clk(clkdiv[18]),.x0(ebx[22]),.y0(eby[22]),.x1(player_dotx),.y1(player_doty),.hit(hitme[22])),
			ch23(.clk(clkdiv[18]),.x0(ebx[23]),.y0(eby[23]),.x1(player_dotx),.y1(player_doty),.hit(hitme[23])),
			ch24(.clk(clkdiv[18]),.x0(ebx[24]),.y0(eby[24]),.x1(player_dotx),.y1(player_doty),.hit(hitme[24])),
			ch25(.clk(clkdiv[18]),.x0(ebx[25]),.y0(eby[25]),.x1(player_dotx),.y1(player_doty),.hit(hitme[25])),
			ch26(.clk(clkdiv[18]),.x0(ebx[26]),.y0(eby[26]),.x1(player_dotx),.y1(player_doty),.hit(hitme[26])),
			ch27(.clk(clkdiv[18]),.x0(ebx[27]),.y0(eby[27]),.x1(player_dotx),.y1(player_doty),.hit(hitme[27])),
			ch28(.clk(clkdiv[18]),.x0(ebx[28]),.y0(eby[28]),.x1(player_dotx),.y1(player_doty),.hit(hitme[28])),
			ch29(.clk(clkdiv[18]),.x0(ebx[29]),.y0(eby[29]),.x1(player_dotx),.y1(player_doty),.hit(hitme[29])),
			ch30(.clk(clkdiv[18]),.x0(ebx[30]),.y0(eby[30]),.x1(player_dotx),.y1(player_doty),.hit(hitme[30])),
			ch31(.clk(clkdiv[18]),.x0(ebx[31]),.y0(eby[31]),.x1(player_dotx),.y1(player_doty),.hit(hitme[31])),
			ch32(.clk(clkdiv[18]),.x0(ebx[32]),.y0(eby[32]),.x1(player_dotx),.y1(player_doty),.hit(hitme[32])),
			ch33(.clk(clkdiv[18]),.x0(ebx[33]),.y0(eby[33]),.x1(player_dotx),.y1(player_doty),.hit(hitme[33])),
			ch34(.clk(clkdiv[18]),.x0(ebx[34]),.y0(eby[34]),.x1(player_dotx),.y1(player_doty),.hit(hitme[34])),
			ch35(.clk(clkdiv[18]),.x0(ebx[35]),.y0(eby[35]),.x1(player_dotx),.y1(player_doty),.hit(hitme[35])),
			ch36(.clk(clkdiv[18]),.x0(ebx[36]),.y0(eby[36]),.x1(player_dotx),.y1(player_doty),.hit(hitme[36])),
			ch37(.clk(clkdiv[18]),.x0(ebx[37]),.y0(eby[37]),.x1(player_dotx),.y1(player_doty),.hit(hitme[37])),
			ch38(.clk(clkdiv[18]),.x0(ebx[38]),.y0(eby[38]),.x1(player_dotx),.y1(player_doty),.hit(hitme[38]));
	//player bulet
	CheckHit #(30) 
			hite0(.clk(clkdiv[18]),.x0(enermyx+13),.y0(enermyy+25),.x1(mbx[0]),.y1(mby[0]),.hit(hitenermy[0])),
			hite1(.clk(clkdiv[18]),.x0(enermyx+13),.y0(enermyy+25),.x1(mbx[1]),.y1(mby[1]),.hit(hitenermy[1])),
			hite2(.clk(clkdiv[18]),.x0(enermyx+13),.y0(enermyy+25),.x1(mbx[2]),.y1(mby[2]),.hit(hitenermy[2])),
			hite3(.clk(clkdiv[18]),.x0(enermyx+13),.y0(enermyy+25),.x1(mbx[3]),.y1(mby[3]),.hit(hitenermy[3])),
			hite4(.clk(clkdiv[18]),.x0(enermyx+13),.y0(enermyy+25),.x1(mbx[4]),.y1(mby[4]),.hit(hitenermy[4])),
			hite5(.clk(clkdiv[18]),.x0(enermyx+13),.y0(enermyy+25),.x1(mbx[5]),.y1(mby[5]),.hit(hitenermy[5])),
			hite6(.clk(clkdiv[18]),.x0(enermyx+13),.y0(enermyy+25),.x1(mbx[6]),.y1(mby[6]),.hit(hitenermy[6])),
			hite7(.clk(clkdiv[18]),.x0(enermyx+13),.y0(enermyy+25),.x1(mbx[7]),.y1(mby[7]),.hit(hitenermy[7]));	


	assign ebx2[0] = (col_addr-ebx[0])*(col_addr-ebx[0]);assign eby2[0] = (row_addr-eby[0])*(row_addr-eby[0]);
	assign ebx2[1] = (col_addr-ebx[1])*(col_addr-ebx[1]);assign eby2[1] = (row_addr-eby[1])*(row_addr-eby[1]);
	assign ebx2[2] = (col_addr-ebx[2])*(col_addr-ebx[2]);assign eby2[2] = (row_addr-eby[2])*(row_addr-eby[2]);
	assign ebx2[3] = (col_addr-ebx[3])*(col_addr-ebx[3]);assign eby2[3] = (row_addr-eby[3])*(row_addr-eby[3]);	
	assign ebx2[4] = (col_addr-ebx[4])*(col_addr-ebx[4]);assign eby2[4] = (row_addr-eby[4])*(row_addr-eby[4]);
	assign ebx2[5] = (col_addr-ebx[5])*(col_addr-ebx[5]);assign eby2[5] = (row_addr-eby[5])*(row_addr-eby[5]);
	assign ebx2[6] = (col_addr-ebx[6])*(col_addr-ebx[6]);assign eby2[6] = (row_addr-eby[6])*(row_addr-eby[6]);
	assign ebx2[7] = (col_addr-ebx[7])*(col_addr-ebx[7]);assign eby2[7] = (row_addr-eby[7])*(row_addr-eby[7]);
	assign ebx2[8] = (col_addr-ebx[8])*(col_addr-ebx[8]);assign eby2[8] = (row_addr-eby[8])*(row_addr-eby[8]);
	assign ebx2[9] = (col_addr-ebx[9])*(col_addr-ebx[9]);assign eby2[9] = (row_addr-eby[9])*(row_addr-eby[9]);
	assign ebx2[10] = (col_addr-ebx[10])*(col_addr-ebx[10]);assign eby2[10] = (row_addr-eby[10])*(row_addr-eby[10]);
	assign ebx2[11] = (col_addr-ebx[11])*(col_addr-ebx[11]);assign eby2[11] = (row_addr-eby[11])*(row_addr-eby[11]);
	assign ebx2[12] = (col_addr-ebx[12])*(col_addr-ebx[12]);assign eby2[12] = (row_addr-eby[12])*(row_addr-eby[12]);
	assign ebx2[13] = (col_addr-ebx[13])*(col_addr-ebx[13]);assign eby2[13] = (row_addr-eby[13])*(row_addr-eby[13]);	
	assign ebx2[14] = (col_addr-ebx[14])*(col_addr-ebx[14]);assign eby2[14] = (row_addr-eby[14])*(row_addr-eby[14]);
	assign ebx2[15] = (col_addr-ebx[15])*(col_addr-ebx[15]);assign eby2[15] = (row_addr-eby[15])*(row_addr-eby[15]);
	assign ebx2[16] = (col_addr-ebx[16])*(col_addr-ebx[16]);assign eby2[16] = (row_addr-eby[16])*(row_addr-eby[16]);
	assign ebx2[17] = (col_addr-ebx[17])*(col_addr-ebx[17]);assign eby2[17] = (row_addr-eby[17])*(row_addr-eby[17]);
	assign ebx2[18] = (col_addr-ebx[18])*(col_addr-ebx[18]);assign eby2[18] = (row_addr-eby[18])*(row_addr-eby[18]);
	assign ebx2[19] = (col_addr-ebx[19])*(col_addr-ebx[19]);assign eby2[19] = (row_addr-eby[19])*(row_addr-eby[19]);
	assign ebx2[20] = (col_addr-ebx[20])*(col_addr-ebx[20]);assign eby2[20] = (row_addr-eby[20])*(row_addr-eby[20]);
	assign ebx2[21] = (col_addr-ebx[21])*(col_addr-ebx[21]);assign eby2[21] = (row_addr-eby[21])*(row_addr-eby[21]);
	assign ebx2[22] = (col_addr-ebx[22])*(col_addr-ebx[22]);assign eby2[22] = (row_addr-eby[22])*(row_addr-eby[22]);
	assign ebx2[23] = (col_addr-ebx[23])*(col_addr-ebx[23]);assign eby2[23] = (row_addr-eby[23])*(row_addr-eby[23]);	
	assign ebx2[24] = (col_addr-ebx[24])*(col_addr-ebx[24]);assign eby2[24] = (row_addr-eby[24])*(row_addr-eby[24]);
	assign ebx2[25] = (col_addr-ebx[25])*(col_addr-ebx[25]);assign eby2[25] = (row_addr-eby[25])*(row_addr-eby[25]);
	assign ebx2[26] = (col_addr-ebx[26])*(col_addr-ebx[26]);assign eby2[26] = (row_addr-eby[26])*(row_addr-eby[26]);
	assign ebx2[27] = (col_addr-ebx[27])*(col_addr-ebx[27]);assign eby2[27] = (row_addr-eby[27])*(row_addr-eby[27]);
	assign ebx2[28] = (col_addr-ebx[28])*(col_addr-ebx[28]);assign eby2[28] = (row_addr-eby[28])*(row_addr-eby[28]);
	assign ebx2[29] = (col_addr-ebx[29])*(col_addr-ebx[29]);assign eby2[29] = (row_addr-eby[29])*(row_addr-eby[29]);
	assign ebx2[30] = (col_addr-ebx[30])*(col_addr-ebx[30]);assign eby2[30] = (row_addr-eby[30])*(row_addr-eby[30]);
	assign ebx2[31] = (col_addr-ebx[31])*(col_addr-ebx[31]);assign eby2[31] = (row_addr-eby[31])*(row_addr-eby[31]);
	assign ebx2[32] = (col_addr-ebx[32])*(col_addr-ebx[32]);assign eby2[32] = (row_addr-eby[32])*(row_addr-eby[32]);
	assign ebx2[33] = (col_addr-ebx[33])*(col_addr-ebx[33]);assign eby2[33] = (row_addr-eby[33])*(row_addr-eby[33]);	
	assign ebx2[34] = (col_addr-ebx[34])*(col_addr-ebx[34]);assign eby2[34] = (row_addr-eby[34])*(row_addr-eby[34]);
	assign ebx2[35] = (col_addr-ebx[35])*(col_addr-ebx[35]);assign eby2[35] = (row_addr-eby[35])*(row_addr-eby[35]);
	assign ebx2[36] = (col_addr-ebx[36])*(col_addr-ebx[36]);assign eby2[36] = (row_addr-eby[36])*(row_addr-eby[36]);
	assign ebx2[37] = (col_addr-ebx[37])*(col_addr-ebx[37]);assign eby2[37] = (row_addr-eby[37])*(row_addr-eby[37]);
	assign ebx2[38] = (col_addr-ebx[38])*(col_addr-ebx[38]);assign eby2[38] = (row_addr-eby[38])*(row_addr-eby[38]);

	assign dead_ptb = 
		hitme[0]|hitme[1]|hitme[2]|hitme[3]|hitme[4]|hitme[5]|hitme[6]|hitme[7];
	assign dead_hv = 
		hitme[8]|hitme[9]|hitme[10]|hitme[11]|hitme[12]|hitme[13]|
		hitme[14]|hitme[15]|hitme[16]|hitme[17]|hitme[18]|hitme[19]|hitme[20];
	assign dead_sph = 
		hitme[21]|hitme[22]|hitme[23]|hitme[24]|hitme[25]|hitme[26]|hitme[27]|hitme[28]|hitme[29]|
		hitme[30]|hitme[31]|hitme[32]|hitme[33]|hitme[34]|hitme[35]|hitme[36]|hitme[37]|hitme[38];
	assign dead = 
		(SW[15])?1'b0:
			(boss_state==0)?dead_hv:
				((boss_state==1)?dead_ptb:
					((boss_state==2)?(dead_hv|dead_ptb):
						(dead_hv|dead_ptb|dead_sph)));
		
	assign hite[0] = ~bullet_cnt[0]&hitenermy[0];
	assign hite[1] = ~bullet_cnt[1]&hitenermy[1];
	assign hite[2] = ~bullet_cnt[2]&hitenermy[2];
	assign hite[3] = ~bullet_cnt[3]&hitenermy[3];
	assign hite[4] = ~bullet_cnt[4]&hitenermy[4];
	assign hite[5] = ~bullet_cnt[5]&hitenermy[5];
	assign hite[6] = ~bullet_cnt[6]&hitenermy[6];
	assign hite[7] = ~bullet_cnt[7]&hitenermy[7];
	
	assign bullet_ptb = 
		(ebx2[0]+eby2[0]<=`bullet_r&&~ptb_wait[0])||
		(ebx2[1]+eby2[1]<=`bullet_r&&~ptb_wait[1])||
		(ebx2[2]+eby2[2]<=`bullet_r&&~ptb_wait[2])||
		(ebx2[3]+eby2[3]<=`bullet_r&&~ptb_wait[3])||
		(ebx2[4]+eby2[4]<=`bullet_r&&~ptb_wait[4])||
		(ebx2[5]+eby2[5]<=`bullet_r&&~ptb_wait[5])||
		(ebx2[6]+eby2[6]<=`bullet_r&&~ptb_wait[6])||
		(ebx2[7]+eby2[7]<=`bullet_r&&~ptb_wait[7]);
	assign bullet_sphere = 
		(ebx2[21]+eby2[21]<=`bullet_r&&~sph_wait[0])||(ebx2[22]+eby2[22]<=`bullet_r&&~sph_wait[1])||
		(ebx2[23]+eby2[23]<=`bullet_r&&~sph_wait[2])||(ebx2[24]+eby2[24]<=`bullet_r&&~sph_wait[3])||
		(ebx2[25]+eby2[25]<=`bullet_r&&~sph_wait[4])||(ebx2[26]+eby2[26]<=`bullet_r&&~sph_wait[5])||
		(ebx2[27]+eby2[27]<=`bullet_r&&~sph_wait[6])||(ebx2[28]+eby2[28]<=`bullet_r&&~sph_wait[7])||
		(ebx2[29]+eby2[29]<=`bullet_r&&~sph_wait[8])||(ebx2[30]+eby2[30]<=`bullet_r&&~sph_wait[9])||
		(ebx2[31]+eby2[31]<=`bullet_r&&~sph_wait[10])||(ebx2[32]+eby2[32]<=`bullet_r&&~sph_wait[11])||
		(ebx2[33]+eby2[33]<=`bullet_r&&~sph_wait[12])||(ebx2[34]+eby2[34]<=`bullet_r&&~sph_wait[13])||
		(ebx2[35]+eby2[35]<=`bullet_r&&~sph_wait[14])||(ebx2[36]+eby2[36]<=`bullet_r&&~sph_wait[15])||
		(ebx2[37]+eby2[37]<=`bullet_r&&~sph_wait[16])||(ebx2[38]+eby2[38]<=`bullet_r&&~sph_wait[17]);
	assign bullet_hv = 
		(ebx2[8]+eby2[8]<=`bullet_r)||(ebx2[9]+eby2[9]<=`bullet_r)||
		(ebx2[10]+eby2[10]<=`bullet_r)||(ebx2[11]+eby2[11]<=`bullet_r)||
		(ebx2[12]+eby2[12]<=`bullet_r)||(ebx2[13]+eby2[13]<=`bullet_r)||
		(ebx2[14]+eby2[14]<=`bullet_r)||(ebx2[15]+eby2[15]<=`bullet_r)||
		(ebx2[16]+eby2[16]<=`bullet_r)||(ebx2[17]+eby2[17]<=`bullet_r)||
		(ebx2[18]+eby2[18]<=`bullet_r)||(ebx2[19]+eby2[19]<=`bullet_r)||
		(ebx2[20]+eby2[20]<=`bullet_r);
	assign bullet_mode = 
		(boss_state==0)?bullet_hv:
			((boss_state==1)?bullet_ptb:
				((boss_state==2)?(bullet_ptb|bullet_hv):
					(bullet_ptb|bullet_hv|bullet_sphere)));
endmodule
